#ifndef BSP_GENERATOR_H
#define BSP_GENERATOR_H

#include <vector>
#include "random.h"

struct Room
{
	Room(int, int, int, int);
	int x1;
	int x2;
	int y1;
	int y2;
};

struct Tree_Node
{
	Tree_Node(Tree_Node *, int, int, int, int);
	~Tree_Node();
	bool isLeaf();
	bool vertical;
	bool hasldoor;
	bool hasrdoor;
	bool hastdoor;
	bool hasbdoor;
	Room *room;
	Tree_Node *left;
	Tree_Node *parent;
	Tree_Node *right;
};

class Tree
{
public:
	Tree(int, int);
	~Tree();
	Tree_Node *head();
	void printTree();
	
private:
	Tree_Node *HEAD;
	void printTreeHelper(Tree_Node *);
};

class BSP_Generator
{
public:
	BSP_Generator(Mersenne_Twister *, int, int, bool, bool);
	~BSP_Generator();
	void printRooms();
	void printDungeon();
	char isAt(int, int);
	
private:
	bool HASDOWNSTAIRS;
	bool HASUPSTAIRS;
	int WIDTH;
	int HEIGHT;
	Tree *BSP;
	Mersenne_Twister *RNG;
	std::vector<char> MAP;
	void generateDungeon();
	void generateHelper(Tree_Node *);
	void printHelper(Tree_Node *);
	void generateWalls();
	void generateWallHelper(Tree_Node *);
	void generateDoors();
	void generateDoorHelper(Tree_Node *);
	void generateStairs();
};

#endif
